<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>sampleFile - OpenGrok cross reference for /sampleFile</title></head><body>
<script type="text/javascript">/* <![CDATA[ */
function get_sym_list(){return [["Function","xf",[["add_suffixes",158],["by_code",75],["by_quoted",73],["by_x",83],["by_y",84],["check_duplicate_vars",133],["check_join_vars",103],["dup",116],["dup",134],["i",164],["join_cols",26],["missing",124],["na",108],["nm",165],["out",163],["standardise_join_by",64],["standardise_join_suffix",143],["x_by",33],["x_is_aux",42],["x_loc",36],["y_aux",41],["y_by",34],["y_loc",50]]]];} /* ]]> */</script><a class="l" name="1" href="#1">1</a><span class="c"># The MIT License (MIT)</span>
<a class="l" name="2" href="#2">2</a><span class="c">#</span>
<a class="l" name="3" href="#3">3</a><span class="c"># Copyright &#169; 2013-2019 RStudio and others.</span>
<a class="l" name="4" href="#4">4</a><span class="c">#</span>
<a class="l" name="5" href="#5">5</a><span class="c"># Permission is hereby granted, free of charge, to any person obtaining a copy</span>
<a class="l" name="6" href="#6">6</a><span class="c"># of this software and associated documentation files (the &#8220;Software&#8221;), to deal</span>
<a class="l" name="7" href="#7">7</a><span class="c"># in the Software without restriction, including without limitation the rights</span>
<a class="l" name="8" href="#8">8</a><span class="c"># to use, copy, modify, merge, publish, distribute, sublicense, <a href="/source/s?path=and/">and</a>/<a href="/source/s?path=and/or">or</a> sell</span>
<a class="l" name="9" href="#9">9</a><span class="c"># copies of the Software, and to permit persons to whom the Software is</span>
<a class="hl" name="10" href="#10">10</a><span class="c"># furnished to do so, subject to the following conditions:</span>
<a class="l" name="11" href="#11">11</a><span class="c">#</span>
<a class="l" name="12" href="#12">12</a><span class="c"># The above copyright notice and this permission notice shall be included in</span>
<a class="l" name="13" href="#13">13</a><span class="c"># all copies or substantial portions of the Software.</span>
<a class="l" name="14" href="#14">14</a><span class="c">#</span>
<a class="l" name="15" href="#15">15</a><span class="c"># THE SOFTWARE IS PROVIDED &#8220;AS IS&#8221;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span>
<a class="l" name="16" href="#16">16</a><span class="c"># IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
<a class="l" name="17" href="#17">17</a><span class="c"># FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span>
<a class="l" name="18" href="#18">18</a><span class="c"># AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
<a class="l" name="19" href="#19">19</a><span class="c"># LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</span>
<a class="hl" name="20" href="#20">20</a><span class="c"># OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE</span>
<a class="l" name="21" href="#21">21</a><span class="c"># SOFTWARE.</span>
<a class="l" name="22" href="#22">22</a><span class="c">#</span>
<a class="l" name="23" href="#23">23</a>
<a class="l" name="24" href="#24">24</a><span class="c"># <a href="/source/s?path=tidyverse/">tidyverse</a>/<a href="/source/s?path=tidyverse/dplyr/">dplyr</a>/<a href="/source/s?path=tidyverse/dplyr/blob/">blob</a>/<a href="/source/s?path=tidyverse/dplyr/blob/master">master</a>/<a href="/source/s?path=/R/">R</a>/<a href="/source/s?path=/R/join-cols.R">join-cols.R</a></span>
<a class="l" name="25" href="#25">25</a>
<a class="l" name="26" href="#26">26</a><a class="xf" name="join_cols"/><a href="/source/s?refs=join_cols" class="xf intelliWindow-symbol" data-definition-place="def">join_cols</a> &lt;- <b>function</b>(<a class="xa" name="x_names"/><a href="/source/s?refs=x_names" class="xa intelliWindow-symbol" data-definition-place="def">x_names</a>, <a class="xa" name="y_names"/><a href="/source/s?refs=y_names" class="xa intelliWindow-symbol" data-definition-place="def">y_names</a>, <a class="xa" name="by"/><a href="/source/s?refs=by" class="xa intelliWindow-symbol" data-definition-place="def">by</a> = <b>NULL</b>, <a class="xa" name="suffix"/><a href="/source/s?refs=suffix" class="xa intelliWindow-symbol" data-definition-place="def">suffix</a> = <a href="/source/s?defs=c" class="intelliWindow-symbol" data-definition-place="undefined-in-file">c</a>(<span class="s">&quot;.x&quot;</span>, <span class="s">&quot;.y&quot;</span>), <a class="xa" name="keep"/><a href="/source/s?refs=keep" class="xa intelliWindow-symbol" data-definition-place="def">keep</a> = <b>FALSE</b>) {
<a class="l" name="27" href="#27">27</a>  <a class="d intelliWindow-symbol" href="#check_duplicate_vars" data-definition-place="defined-in-file">check_duplicate_vars</a>(<a href="/source/s?defs=x_names" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x_names</a>, <span class="s">&quot;x&quot;</span>)
<a class="l" name="28" href="#28">28</a>  <a class="d intelliWindow-symbol" href="#check_duplicate_vars" data-definition-place="defined-in-file">check_duplicate_vars</a>(<a href="/source/s?defs=y_names" class="intelliWindow-symbol" data-definition-place="undefined-in-file">y_names</a>, <span class="s">&quot;y&quot;</span>)
<a class="l" name="29" href="#29">29</a>
<a class="hl" name="30" href="#30">30</a>  <a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a> &lt;- <a class="d intelliWindow-symbol" href="#standardise_join_by" data-definition-place="defined-in-file">standardise_join_by</a>(<a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a>, <a href="/source/s?defs=x_names" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x_names</a> = <a href="/source/s?defs=x_names" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x_names</a>, <a href="/source/s?defs=y_names" class="intelliWindow-symbol" data-definition-place="undefined-in-file">y_names</a> = <a href="/source/s?defs=y_names" class="intelliWindow-symbol" data-definition-place="undefined-in-file">y_names</a>)
<a class="l" name="31" href="#31">31</a>  <a href="/source/s?defs=suffix" class="intelliWindow-symbol" data-definition-place="undefined-in-file">suffix</a> &lt;- <a class="d intelliWindow-symbol" href="#standardise_join_suffix" data-definition-place="defined-in-file">standardise_join_suffix</a>(<a href="/source/s?defs=suffix" class="intelliWindow-symbol" data-definition-place="undefined-in-file">suffix</a>)
<a class="l" name="32" href="#32">32</a>
<a class="l" name="33" href="#33">33</a>  <a class="xf" name="x_by"/><a href="/source/s?refs=x_by" class="xf intelliWindow-symbol" data-definition-place="def">x_by</a> &lt;- <a href="/source/s?defs=set_names" class="intelliWindow-symbol" data-definition-place="undefined-in-file">set_names</a>(<a href="/source/s?defs=match" class="intelliWindow-symbol" data-definition-place="undefined-in-file">match</a>(<a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a>$<a href="/source/s?defs=x" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x</a>, <a href="/source/s?defs=x_names" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x_names</a>), <a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a>$<a href="/source/s?defs=x" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x</a>)
<a class="l" name="34" href="#34">34</a>  <a class="xf" name="y_by"/><a href="/source/s?refs=y_by" class="xf intelliWindow-symbol" data-definition-place="def">y_by</a> &lt;- <a href="/source/s?defs=set_names" class="intelliWindow-symbol" data-definition-place="undefined-in-file">set_names</a>(<a href="/source/s?defs=match" class="intelliWindow-symbol" data-definition-place="undefined-in-file">match</a>(<a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a>$<a href="/source/s?defs=y" class="intelliWindow-symbol" data-definition-place="undefined-in-file">y</a>, <a href="/source/s?defs=y_names" class="intelliWindow-symbol" data-definition-place="undefined-in-file">y_names</a>), <a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a>$<a href="/source/s?defs=x" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x</a>)
<a class="l" name="35" href="#35">35</a>
<a class="l" name="36" href="#36">36</a>  <a class="xf" name="x_loc"/><a href="/source/s?refs=x_loc" class="xf intelliWindow-symbol" data-definition-place="def">x_loc</a> &lt;- <a href="/source/s?defs=seq_along" class="intelliWindow-symbol" data-definition-place="undefined-in-file">seq_along</a>(<a href="/source/s?defs=x_names" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x_names</a>)
<a class="l" name="37" href="#37">37</a>  <a class="d intelliWindow-symbol" href="#names" data-definition-place="defined-in-file">names</a>(<a class="d intelliWindow-symbol" href="#x_loc" data-definition-place="defined-in-file">x_loc</a>) &lt;- <a href="/source/s?defs=x_names" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x_names</a>
<a class="l" name="38" href="#38">38</a>  <b>if</b> (!<a class="d intelliWindow-symbol" href="#keep" data-definition-place="defined-in-file">keep</a>) {
<a class="l" name="39" href="#39">39</a>    <span class="c"># in x_out, key variables need to keep the same name, and aux</span>
<a class="hl" name="40" href="#40">40</a>    <span class="c"># variables need suffixes for duplicates that appear in y_out</span>
<a class="l" name="41" href="#41">41</a>    <a class="xf" name="y_aux"/><a href="/source/s?refs=y_aux" class="xf intelliWindow-symbol" data-definition-place="def">y_aux</a> &lt;- <a href="/source/s?defs=setdiff" class="intelliWindow-symbol" data-definition-place="undefined-in-file">setdiff</a>(<a href="/source/s?defs=y_names" class="intelliWindow-symbol" data-definition-place="undefined-in-file">y_names</a>, <a href="/source/s?defs=c" class="intelliWindow-symbol" data-definition-place="undefined-in-file">c</a>(<a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a>$<a href="/source/s?defs=x" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x</a>, <b>if</b> (!<a class="d intelliWindow-symbol" href="#keep" data-definition-place="defined-in-file">keep</a>) <a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a>$<a href="/source/s?defs=y" class="intelliWindow-symbol" data-definition-place="undefined-in-file">y</a>))
<a class="l" name="42" href="#42">42</a>    <a class="xf" name="x_is_aux"/><a href="/source/s?refs=x_is_aux" class="xf intelliWindow-symbol" data-definition-place="def">x_is_aux</a> &lt;- !<a href="/source/s?defs=x_names" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x_names</a> %<b>in</b>% <a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a>$<a href="/source/s?defs=x" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x</a>
<a class="l" name="43" href="#43">43</a>    <a class="d intelliWindow-symbol" href="#names" data-definition-place="defined-in-file">names</a>(<a class="d intelliWindow-symbol" href="#x_loc" data-definition-place="defined-in-file">x_loc</a>)[<a class="d intelliWindow-symbol" href="#x_is_aux" data-definition-place="defined-in-file">x_is_aux</a>] &lt;- <a class="d intelliWindow-symbol" href="#add_suffixes" data-definition-place="defined-in-file">add_suffixes</a>(<a href="/source/s?defs=x_names" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x_names</a>[<a class="d intelliWindow-symbol" href="#x_is_aux" data-definition-place="defined-in-file">x_is_aux</a>], <a href="/source/s?defs=c" class="intelliWindow-symbol" data-definition-place="undefined-in-file">c</a>(<a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a>$<a href="/source/s?defs=x" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x</a>, <a class="d intelliWindow-symbol" href="#y_aux" data-definition-place="defined-in-file">y_aux</a>), <a href="/source/s?defs=suffix" class="intelliWindow-symbol" data-definition-place="undefined-in-file">suffix</a>$<a href="/source/s?defs=x" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x</a>)
<a class="l" name="44" href="#44">44</a>  } <b>else</b> {
<a class="l" name="45" href="#45">45</a>    <span class="c"># in x_out, key variables and aux variables need suffixes</span>
<a class="l" name="46" href="#46">46</a>    <span class="c"># for duplicates that appear in y_out</span>
<a class="l" name="47" href="#47">47</a>    <a class="d intelliWindow-symbol" href="#names" data-definition-place="defined-in-file">names</a>(<a class="d intelliWindow-symbol" href="#x_loc" data-definition-place="defined-in-file">x_loc</a>) &lt;- <a class="d intelliWindow-symbol" href="#add_suffixes" data-definition-place="defined-in-file">add_suffixes</a>(<a href="/source/s?defs=x_names" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x_names</a>, <a href="/source/s?defs=y_names" class="intelliWindow-symbol" data-definition-place="undefined-in-file">y_names</a>, <a href="/source/s?defs=suffix" class="intelliWindow-symbol" data-definition-place="undefined-in-file">suffix</a>$<a href="/source/s?defs=x" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x</a>)
<a class="l" name="48" href="#48">48</a>  }
<a class="l" name="49" href="#49">49</a>
<a class="hl" name="50" href="#50">50</a>  <a class="xf" name="y_loc"/><a href="/source/s?refs=y_loc" class="xf intelliWindow-symbol" data-definition-place="def">y_loc</a> &lt;- <a href="/source/s?defs=seq_along" class="intelliWindow-symbol" data-definition-place="undefined-in-file">seq_along</a>(<a href="/source/s?defs=y_names" class="intelliWindow-symbol" data-definition-place="undefined-in-file">y_names</a>)
<a class="l" name="51" href="#51">51</a>  <a class="d intelliWindow-symbol" href="#names" data-definition-place="defined-in-file">names</a>(<a class="d intelliWindow-symbol" href="#y_loc" data-definition-place="defined-in-file">y_loc</a>) &lt;- <a class="d intelliWindow-symbol" href="#add_suffixes" data-definition-place="defined-in-file">add_suffixes</a>(<a href="/source/s?defs=y_names" class="intelliWindow-symbol" data-definition-place="undefined-in-file">y_names</a>, <a href="/source/s?defs=x_names" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x_names</a>, <a href="/source/s?defs=suffix" class="intelliWindow-symbol" data-definition-place="undefined-in-file">suffix</a>$<a href="/source/s?defs=y" class="intelliWindow-symbol" data-definition-place="undefined-in-file">y</a>)
<a class="l" name="52" href="#52">52</a>  <b>if</b> (!<a class="d intelliWindow-symbol" href="#keep" data-definition-place="defined-in-file">keep</a>) {
<a class="l" name="53" href="#53">53</a>    <a class="d intelliWindow-symbol" href="#y_loc" data-definition-place="defined-in-file">y_loc</a> &lt;- <a class="d intelliWindow-symbol" href="#y_loc" data-definition-place="defined-in-file">y_loc</a>[!<a href="/source/s?defs=y_names" class="intelliWindow-symbol" data-definition-place="undefined-in-file">y_names</a> %<b>in</b>% <a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a>$<a href="/source/s?defs=y" class="intelliWindow-symbol" data-definition-place="undefined-in-file">y</a>]
<a class="l" name="54" href="#54">54</a>  }
<a class="l" name="55" href="#55">55</a>
<a class="l" name="56" href="#56">56</a>  <span class="c"># key = named location to use for matching</span>
<a class="l" name="57" href="#57">57</a>  <span class="c"># out = named locations to use in output</span>
<a class="l" name="58" href="#58">58</a>  <a href="/source/s?defs=list" class="intelliWindow-symbol" data-definition-place="undefined-in-file">list</a>(
<a class="l" name="59" href="#59">59</a>    <a href="/source/s?defs=x" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x</a> = <a href="/source/s?defs=list" class="intelliWindow-symbol" data-definition-place="undefined-in-file">list</a>(<a href="/source/s?defs=key" class="intelliWindow-symbol" data-definition-place="undefined-in-file">key</a> = <a class="d intelliWindow-symbol" href="#x_by" data-definition-place="defined-in-file">x_by</a>, <a class="d intelliWindow-symbol" href="#out" data-definition-place="defined-in-file">out</a> = <a class="d intelliWindow-symbol" href="#x_loc" data-definition-place="defined-in-file">x_loc</a>),
<a class="hl" name="60" href="#60">60</a>    <a href="/source/s?defs=y" class="intelliWindow-symbol" data-definition-place="undefined-in-file">y</a> = <a href="/source/s?defs=list" class="intelliWindow-symbol" data-definition-place="undefined-in-file">list</a>(<a href="/source/s?defs=key" class="intelliWindow-symbol" data-definition-place="undefined-in-file">key</a> = <a class="d intelliWindow-symbol" href="#y_by" data-definition-place="defined-in-file">y_by</a>, <a class="d intelliWindow-symbol" href="#out" data-definition-place="defined-in-file">out</a> = <a class="d intelliWindow-symbol" href="#y_loc" data-definition-place="defined-in-file">y_loc</a>)
<a class="l" name="61" href="#61">61</a>  )
<a class="l" name="62" href="#62">62</a>}
<a class="l" name="63" href="#63">63</a>
<a class="l" name="64" href="#64">64</a><a class="xf" name="standardise_join_by"/><a href="/source/s?refs=standardise_join_by" class="xf intelliWindow-symbol" data-definition-place="def">standardise_join_by</a> &lt;- <b>function</b>(<a class="xa" name="by"/><a href="/source/s?refs=by" class="xa intelliWindow-symbol" data-definition-place="def">by</a>, <a class="xa" name="x_names"/><a href="/source/s?refs=x_names" class="xa intelliWindow-symbol" data-definition-place="def">x_names</a>, <a class="xa" name="y_names"/><a href="/source/s?refs=y_names" class="xa intelliWindow-symbol" data-definition-place="def">y_names</a>) {
<a class="l" name="65" href="#65">65</a>  <b>if</b> (<a href="/source/s?defs=is.null" class="intelliWindow-symbol" data-definition-place="undefined-in-file">is.null</a>(<a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a>)) {
<a class="l" name="66" href="#66">66</a>    <a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a> &lt;- <a href="/source/s?defs=intersect" class="intelliWindow-symbol" data-definition-place="undefined-in-file">intersect</a>(<a href="/source/s?defs=x_names" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x_names</a>, <a href="/source/s?defs=y_names" class="intelliWindow-symbol" data-definition-place="undefined-in-file">y_names</a>)
<a class="l" name="67" href="#67">67</a>    <b>if</b> (<a href="/source/s?defs=length" class="intelliWindow-symbol" data-definition-place="undefined-in-file">length</a>(<a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a>) == <span class="n">0</span>) {
<a class="l" name="68" href="#68">68</a>      <a href="/source/s?defs=abort" class="intelliWindow-symbol" data-definition-place="undefined-in-file">abort</a>(<a href="/source/s?defs=c" class="intelliWindow-symbol" data-definition-place="undefined-in-file">c</a>(
<a class="l" name="69" href="#69">69</a>        <span class="s">&quot;`by` must be supplied when `x` and `y` have no common variables.&quot;</span>,
<a class="hl" name="70" href="#70">70</a>        <a class="d intelliWindow-symbol" href="#i" data-definition-place="defined-in-file">i</a> = <span class="s">&quot;use by = character()` to perform a cross-join.&quot;</span>
<a class="l" name="71" href="#71">71</a>      ))
<a class="l" name="72" href="#72">72</a>    }
<a class="l" name="73" href="#73">73</a>    <a class="xf" name="by_quoted"/><a href="/source/s?refs=by_quoted" class="xf intelliWindow-symbol" data-definition-place="def">by_quoted</a> &lt;- <a href="/source/s?defs=encodeString" class="intelliWindow-symbol" data-definition-place="undefined-in-file">encodeString</a>(<a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a>, <a href="/source/s?defs=quote" class="intelliWindow-symbol" data-definition-place="undefined-in-file">quote</a> = <span class="s">&apos;&quot;&apos;</span>)
<a class="l" name="74" href="#74">74</a>    <b>if</b> (<a href="/source/s?defs=length" class="intelliWindow-symbol" data-definition-place="undefined-in-file">length</a>(<a class="d intelliWindow-symbol" href="#by_quoted" data-definition-place="defined-in-file">by_quoted</a>) == <span class="n">1L</span>) {
<a class="l" name="75" href="#75">75</a>      <a class="xf" name="by_code"/><a href="/source/s?refs=by_code" class="xf intelliWindow-symbol" data-definition-place="def">by_code</a> &lt;- <a class="d intelliWindow-symbol" href="#by_quoted" data-definition-place="defined-in-file">by_quoted</a>
<a class="l" name="76" href="#76">76</a>    } <b>else</b> {
<a class="l" name="77" href="#77">77</a>      <a class="d intelliWindow-symbol" href="#by_code" data-definition-place="defined-in-file">by_code</a> &lt;- <a href="/source/s?defs=paste0" class="intelliWindow-symbol" data-definition-place="undefined-in-file">paste0</a>(<span class="s">&quot;c(&quot;</span>, <a href="/source/s?defs=paste" class="intelliWindow-symbol" data-definition-place="undefined-in-file">paste</a>(<a class="d intelliWindow-symbol" href="#by_quoted" data-definition-place="defined-in-file">by_quoted</a>, <a href="/source/s?defs=collapse" class="intelliWindow-symbol" data-definition-place="undefined-in-file">collapse</a> = <span class="s">&quot;, &quot;</span>), <span class="s">&quot;)&quot;</span>)
<a class="l" name="78" href="#78">78</a>    }
<a class="l" name="79" href="#79">79</a>    <a href="/source/s?defs=inform" class="intelliWindow-symbol" data-definition-place="undefined-in-file">inform</a>(<a href="/source/s?defs=paste0" class="intelliWindow-symbol" data-definition-place="undefined-in-file">paste0</a>(<span class="s">&quot;Joining, by = &quot;</span>, <a class="d intelliWindow-symbol" href="#by_code" data-definition-place="defined-in-file">by_code</a>))
<a class="hl" name="80" href="#80">80</a>
<a class="l" name="81" href="#81">81</a>    <a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a> &lt;- <a href="/source/s?defs=list" class="intelliWindow-symbol" data-definition-place="undefined-in-file">list</a>(<a href="/source/s?defs=x" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x</a> = <a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a>, <a href="/source/s?defs=y" class="intelliWindow-symbol" data-definition-place="undefined-in-file">y</a> = <a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a>)
<a class="l" name="82" href="#82">82</a>  } <b>else</b> <b>if</b> (<a href="/source/s?defs=is.character" class="intelliWindow-symbol" data-definition-place="undefined-in-file">is.character</a>(<a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a>)) {
<a class="l" name="83" href="#83">83</a>    <a class="xf" name="by_x"/><a href="/source/s?refs=by_x" class="xf intelliWindow-symbol" data-definition-place="def">by_x</a> &lt;- <a class="d intelliWindow-symbol" href="#names" data-definition-place="defined-in-file">names</a>(<a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a>) %||% <a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a>
<a class="l" name="84" href="#84">84</a>    <a class="xf" name="by_y"/><a href="/source/s?refs=by_y" class="xf intelliWindow-symbol" data-definition-place="def">by_y</a> &lt;- <a href="/source/s?defs=unname" class="intelliWindow-symbol" data-definition-place="undefined-in-file">unname</a>(<a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a>)
<a class="l" name="85" href="#85">85</a>
<a class="l" name="86" href="#86">86</a>    <span class="c"># If x partially named, assume unnamed are the same in both tables</span>
<a class="l" name="87" href="#87">87</a>    <a class="d intelliWindow-symbol" href="#by_x" data-definition-place="defined-in-file">by_x</a>[<a class="d intelliWindow-symbol" href="#by_x" data-definition-place="defined-in-file">by_x</a> == <span class="s">&quot;&quot;</span>] &lt;- <a class="d intelliWindow-symbol" href="#by_y" data-definition-place="defined-in-file">by_y</a>[<a class="d intelliWindow-symbol" href="#by_x" data-definition-place="defined-in-file">by_x</a> == <span class="s">&quot;&quot;</span>]
<a class="l" name="88" href="#88">88</a>
<a class="l" name="89" href="#89">89</a>    <a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a> &lt;- <a href="/source/s?defs=list" class="intelliWindow-symbol" data-definition-place="undefined-in-file">list</a>(<a href="/source/s?defs=x" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x</a> = <a class="d intelliWindow-symbol" href="#by_x" data-definition-place="defined-in-file">by_x</a>, <a href="/source/s?defs=y" class="intelliWindow-symbol" data-definition-place="undefined-in-file">y</a> = <a class="d intelliWindow-symbol" href="#by_y" data-definition-place="defined-in-file">by_y</a>)
<a class="hl" name="90" href="#90">90</a>  } <b>else</b> <b>if</b> (<a href="/source/s?defs=is.list" class="intelliWindow-symbol" data-definition-place="undefined-in-file">is.list</a>(<a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a>)) {
<a class="l" name="91" href="#91">91</a>    <span class="c"># TODO: check lengths</span>
<a class="l" name="92" href="#92">92</a>    <a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a> &lt;- <a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a>[<a href="/source/s?defs=c" class="intelliWindow-symbol" data-definition-place="undefined-in-file">c</a>(<span class="s">&quot;x&quot;</span>, <span class="s">&quot;y&quot;</span>)]
<a class="l" name="93" href="#93">93</a>  } <b>else</b> {
<a class="l" name="94" href="#94">94</a>    <a href="/source/s?defs=bad_args" class="intelliWindow-symbol" data-definition-place="undefined-in-file">bad_args</a>(<span class="s">&quot;by&quot;</span>, <span class="s">&quot;must be a (named) character vector, list, or NULL, not {friendly_type_of(by)}.&quot;</span>)
<a class="l" name="95" href="#95">95</a>  }
<a class="l" name="96" href="#96">96</a>
<a class="l" name="97" href="#97">97</a>  <a class="d intelliWindow-symbol" href="#check_join_vars" data-definition-place="defined-in-file">check_join_vars</a>(<a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a>$<a href="/source/s?defs=x" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x</a>, <a href="/source/s?defs=x_names" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x_names</a>)
<a class="l" name="98" href="#98">98</a>  <a class="d intelliWindow-symbol" href="#check_join_vars" data-definition-place="defined-in-file">check_join_vars</a>(<a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a>$<a href="/source/s?defs=y" class="intelliWindow-symbol" data-definition-place="undefined-in-file">y</a>, <a href="/source/s?defs=y_names" class="intelliWindow-symbol" data-definition-place="undefined-in-file">y_names</a>)
<a class="l" name="99" href="#99">99</a>
<a class="hl" name="100" href="#100">100</a>  <a href="/source/s?defs=by" class="intelliWindow-symbol" data-definition-place="undefined-in-file">by</a>
<a class="l" name="101" href="#101">101</a>}
<a class="l" name="102" href="#102">102</a>
<a class="l" name="103" href="#103">103</a><a class="xf" name="check_join_vars"/><a href="/source/s?refs=check_join_vars" class="xf intelliWindow-symbol" data-definition-place="def">check_join_vars</a> &lt;- <b>function</b>(<a class="xa" name="vars"/><a href="/source/s?refs=vars" class="xa intelliWindow-symbol" data-definition-place="def">vars</a>, <a class="xa" name="names"/><a href="/source/s?refs=names" class="xa intelliWindow-symbol" data-definition-place="def">names</a>) {
<a class="l" name="104" href="#104">104</a>  <b>if</b> (!<a href="/source/s?defs=is.character" class="intelliWindow-symbol" data-definition-place="undefined-in-file">is.character</a>(<a href="/source/s?defs=vars" class="intelliWindow-symbol" data-definition-place="undefined-in-file">vars</a>)) {
<a class="l" name="105" href="#105">105</a>    <a href="/source/s?defs=abort" class="intelliWindow-symbol" data-definition-place="undefined-in-file">abort</a>(<span class="s">&quot;join columns must be character vectors.&quot;</span>)
<a class="l" name="106" href="#106">106</a>  }
<a class="l" name="107" href="#107">107</a>
<a class="l" name="108" href="#108">108</a>  <a class="xf" name="na"/><a href="/source/s?refs=na" class="xf intelliWindow-symbol" data-definition-place="def">na</a> &lt;- <a href="/source/s?defs=is.na" class="intelliWindow-symbol" data-definition-place="undefined-in-file">is.na</a>(<a href="/source/s?defs=vars" class="intelliWindow-symbol" data-definition-place="undefined-in-file">vars</a>)
<a class="l" name="109" href="#109">109</a>  <b>if</b> (<a href="/source/s?defs=any" class="intelliWindow-symbol" data-definition-place="undefined-in-file">any</a>(<a class="d intelliWindow-symbol" href="#na" data-definition-place="defined-in-file">na</a>)) {
<a class="hl" name="110" href="#110">110</a>    <a href="/source/s?defs=abort" class="intelliWindow-symbol" data-definition-place="undefined-in-file">abort</a>(<a href="/source/s?defs=c" class="intelliWindow-symbol" data-definition-place="undefined-in-file">c</a>(
<a class="l" name="111" href="#111">111</a>      <span class="s">&quot;Join columns must be not NA.&quot;</span>,
<a class="l" name="112" href="#112">112</a>      <a href="/source/s?defs=x" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x</a> = <a href="/source/s?defs=glue" class="intelliWindow-symbol" data-definition-place="undefined-in-file">glue</a>(<span class="s">&quot;Problem at position {err_vars(na)}.&quot;</span>)
<a class="l" name="113" href="#113">113</a>    ))
<a class="l" name="114" href="#114">114</a>  }
<a class="l" name="115" href="#115">115</a>
<a class="l" name="116" href="#116">116</a>  <a class="xf" name="dup"/><a href="/source/s?refs=dup" class="xf intelliWindow-symbol" data-definition-place="def">dup</a> &lt;- <a href="/source/s?defs=duplicated" class="intelliWindow-symbol" data-definition-place="undefined-in-file">duplicated</a>(<a href="/source/s?defs=vars" class="intelliWindow-symbol" data-definition-place="undefined-in-file">vars</a>)
<a class="l" name="117" href="#117">117</a>  <b>if</b> (<a href="/source/s?defs=any" class="intelliWindow-symbol" data-definition-place="undefined-in-file">any</a>(<a href="/source/s?defs=dup" class="intelliWindow-symbol" data-definition-place="undefined-in-file">dup</a>)) {
<a class="l" name="118" href="#118">118</a>    <a href="/source/s?defs=abort" class="intelliWindow-symbol" data-definition-place="undefined-in-file">abort</a>(<a href="/source/s?defs=c" class="intelliWindow-symbol" data-definition-place="undefined-in-file">c</a>(
<a class="l" name="119" href="#119">119</a>      <span class="s">&quot;Join columns must be unique.&quot;</span>,
<a class="hl" name="120" href="#120">120</a>      <a href="/source/s?defs=x" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x</a> = <a href="/source/s?defs=glue" class="intelliWindow-symbol" data-definition-place="undefined-in-file">glue</a>(<span class="s">&quot;Problem at position {err_vars(dup)}.&quot;</span>)
<a class="l" name="121" href="#121">121</a>    ))
<a class="l" name="122" href="#122">122</a>  }
<a class="l" name="123" href="#123">123</a>
<a class="l" name="124" href="#124">124</a>  <a class="xf" name="missing"/><a href="/source/s?refs=missing" class="xf intelliWindow-symbol" data-definition-place="def">missing</a> &lt;- <a href="/source/s?defs=setdiff" class="intelliWindow-symbol" data-definition-place="undefined-in-file">setdiff</a>(<a href="/source/s?defs=vars" class="intelliWindow-symbol" data-definition-place="undefined-in-file">vars</a>, <a class="d intelliWindow-symbol" href="#names" data-definition-place="defined-in-file">names</a>)
<a class="l" name="125" href="#125">125</a>  <b>if</b> (<a href="/source/s?defs=length" class="intelliWindow-symbol" data-definition-place="undefined-in-file">length</a>(<a class="d intelliWindow-symbol" href="#missing" data-definition-place="defined-in-file">missing</a>) &gt; <span class="n">0</span>) {
<a class="l" name="126" href="#126">126</a>    <a href="/source/s?defs=abort" class="intelliWindow-symbol" data-definition-place="undefined-in-file">abort</a>(<a href="/source/s?defs=c" class="intelliWindow-symbol" data-definition-place="undefined-in-file">c</a>(
<a class="l" name="127" href="#127">127</a>      <span class="s">&quot;Join columns must be present in data.&quot;</span>,
<a class="l" name="128" href="#128">128</a>      <a href="/source/s?defs=x" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x</a> = <a href="/source/s?defs=glue" class="intelliWindow-symbol" data-definition-place="undefined-in-file">glue</a>(<span class="s">&quot;Problem with {err_vars(missing)}.&quot;</span>)
<a class="l" name="129" href="#129">129</a>    ))
<a class="hl" name="130" href="#130">130</a>  }
<a class="l" name="131" href="#131">131</a>}
<a class="l" name="132" href="#132">132</a>
<a class="l" name="133" href="#133">133</a><a class="xf" name="check_duplicate_vars"/><a href="/source/s?refs=check_duplicate_vars" class="xf intelliWindow-symbol" data-definition-place="def">check_duplicate_vars</a> &lt;- <b>function</b>(<a class="xa" name="vars"/><a href="/source/s?refs=vars" class="xa intelliWindow-symbol" data-definition-place="def">vars</a>, <a class="xa" name="input"/><a href="/source/s?refs=input" class="xa intelliWindow-symbol" data-definition-place="def">input</a>) {
<a class="l" name="134" href="#134">134</a>  <a class="xf" name="dup"/><a href="/source/s?refs=dup" class="xf intelliWindow-symbol" data-definition-place="def">dup</a> &lt;- <a href="/source/s?defs=duplicated" class="intelliWindow-symbol" data-definition-place="undefined-in-file">duplicated</a>(<a href="/source/s?defs=vars" class="intelliWindow-symbol" data-definition-place="undefined-in-file">vars</a>)
<a class="l" name="135" href="#135">135</a>  <b>if</b> (<a href="/source/s?defs=any" class="intelliWindow-symbol" data-definition-place="undefined-in-file">any</a>(<a href="/source/s?defs=dup" class="intelliWindow-symbol" data-definition-place="undefined-in-file">dup</a>)) {
<a class="l" name="136" href="#136">136</a>    <a href="/source/s?defs=abort" class="intelliWindow-symbol" data-definition-place="undefined-in-file">abort</a>(<a href="/source/s?defs=c" class="intelliWindow-symbol" data-definition-place="undefined-in-file">c</a>(
<a class="l" name="137" href="#137">137</a>      <a href="/source/s?defs=glue" class="intelliWindow-symbol" data-definition-place="undefined-in-file">glue</a>(<span class="s">&quot;Input columns in `{input}` must be unique.&quot;</span>),
<a class="l" name="138" href="#138">138</a>      <a href="/source/s?defs=x" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x</a> = <a href="/source/s?defs=glue" class="intelliWindow-symbol" data-definition-place="undefined-in-file">glue</a>(<span class="s">&quot;Problem with {err_vars(vars[dup])}.&quot;</span>)
<a class="l" name="139" href="#139">139</a>    ))
<a class="hl" name="140" href="#140">140</a>  }
<a class="l" name="141" href="#141">141</a>}
<a class="l" name="142" href="#142">142</a>
<a class="l" name="143" href="#143">143</a><a class="xf" name="standardise_join_suffix"/><a href="/source/s?refs=standardise_join_suffix" class="xf intelliWindow-symbol" data-definition-place="def">standardise_join_suffix</a> &lt;- <b>function</b>(<a class="xa" name="x"/><a href="/source/s?refs=x" class="xa intelliWindow-symbol" data-definition-place="def">x</a>) {
<a class="l" name="144" href="#144">144</a>  <b>if</b> (!<a href="/source/s?defs=is.character" class="intelliWindow-symbol" data-definition-place="undefined-in-file">is.character</a>(<a href="/source/s?defs=x" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x</a>) || <a href="/source/s?defs=length" class="intelliWindow-symbol" data-definition-place="undefined-in-file">length</a>(<a href="/source/s?defs=x" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x</a>) != <span class="n">2</span>) {
<a class="l" name="145" href="#145">145</a>    <a href="/source/s?defs=abort" class="intelliWindow-symbol" data-definition-place="undefined-in-file">abort</a>(<a href="/source/s?defs=c" class="intelliWindow-symbol" data-definition-place="undefined-in-file">c</a>(
<a class="l" name="146" href="#146">146</a>      <span class="s">&quot;`suffix` must be a character vector of length 2.&quot;</span>,
<a class="l" name="147" href="#147">147</a>      <a class="d intelliWindow-symbol" href="#i" data-definition-place="defined-in-file">i</a> = <a href="/source/s?defs=glue" class="intelliWindow-symbol" data-definition-place="undefined-in-file">glue</a>(<span class="s">&quot;suffix is {friendly_type_of(x)} of length {length(x)}.&quot;</span>)
<a class="l" name="148" href="#148">148</a>    ))
<a class="l" name="149" href="#149">149</a>  }
<a class="hl" name="150" href="#150">150</a>
<a class="l" name="151" href="#151">151</a>  <b>if</b> (<a href="/source/s?defs=any" class="intelliWindow-symbol" data-definition-place="undefined-in-file">any</a>(<a href="/source/s?defs=is.na" class="intelliWindow-symbol" data-definition-place="undefined-in-file">is.na</a>(<a href="/source/s?defs=x" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x</a>))) {
<a class="l" name="152" href="#152">152</a>    <a href="/source/s?defs=bad_args" class="intelliWindow-symbol" data-definition-place="undefined-in-file">bad_args</a>(<span class="s">&quot;suffix&quot;</span>, <span class="s">&quot;can&apos;t be NA.&quot;</span>)
<a class="l" name="153" href="#153">153</a>  }
<a class="l" name="154" href="#154">154</a>
<a class="l" name="155" href="#155">155</a>  <a href="/source/s?defs=list" class="intelliWindow-symbol" data-definition-place="undefined-in-file">list</a>(<a href="/source/s?defs=x" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x</a> = <a href="/source/s?defs=x" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x</a>[[<span class="n">1</span>]], <a href="/source/s?defs=y" class="intelliWindow-symbol" data-definition-place="undefined-in-file">y</a> = <a href="/source/s?defs=x" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x</a>[[<span class="n">2</span>]])
<a class="l" name="156" href="#156">156</a>}
<a class="l" name="157" href="#157">157</a>
<a class="l" name="158" href="#158">158</a><a class="xf" name="add_suffixes"/><a href="/source/s?refs=add_suffixes" class="xf intelliWindow-symbol" data-definition-place="def">add_suffixes</a> &lt;- <b>function</b>(<a class="xa" name="x"/><a href="/source/s?refs=x" class="xa intelliWindow-symbol" data-definition-place="def">x</a>, <a class="xa" name="y"/><a href="/source/s?refs=y" class="xa intelliWindow-symbol" data-definition-place="def">y</a>, <a class="xa" name="suffix"/><a href="/source/s?refs=suffix" class="xa intelliWindow-symbol" data-definition-place="def">suffix</a>) {
<a class="l" name="159" href="#159">159</a>  <b>if</b> (<a href="/source/s?defs=identical" class="intelliWindow-symbol" data-definition-place="undefined-in-file">identical</a>(<a href="/source/s?defs=suffix" class="intelliWindow-symbol" data-definition-place="undefined-in-file">suffix</a>, <span class="s">&quot;&quot;</span>)) {
<a class="hl" name="160" href="#160">160</a>    <a href="/source/s?defs=return" class="intelliWindow-symbol" data-definition-place="undefined-in-file">return</a>(<a href="/source/s?defs=x" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x</a>)
<a class="l" name="161" href="#161">161</a>  }
<a class="l" name="162" href="#162">162</a>
<a class="l" name="163" href="#163">163</a>  <a class="xf" name="out"/><a href="/source/s?refs=out" class="xf intelliWindow-symbol" data-definition-place="def">out</a> &lt;- <a href="/source/s?defs=rep_along" class="intelliWindow-symbol" data-definition-place="undefined-in-file">rep_along</a>(<a href="/source/s?defs=x" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x</a>, <a href="/source/s?defs=na_chr" class="intelliWindow-symbol" data-definition-place="undefined-in-file">na_chr</a>)
<a class="l" name="164" href="#164">164</a>  <b>for</b> (<a class="xf" name="i"/><a href="/source/s?refs=i" class="xf intelliWindow-symbol" data-definition-place="def">i</a> <b>in</b> <a href="/source/s?defs=seq_along" class="intelliWindow-symbol" data-definition-place="undefined-in-file">seq_along</a>(<a href="/source/s?defs=x" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x</a>)) {
<a class="l" name="165" href="#165">165</a>    <a class="xf" name="nm"/><a href="/source/s?refs=nm" class="xf intelliWindow-symbol" data-definition-place="def">nm</a> &lt;- <a href="/source/s?defs=x" class="intelliWindow-symbol" data-definition-place="undefined-in-file">x</a>[[<a class="d intelliWindow-symbol" href="#i" data-definition-place="defined-in-file">i</a>]]
<a class="l" name="166" href="#166">166</a>    <b>while</b> (<a class="d intelliWindow-symbol" href="#nm" data-definition-place="defined-in-file">nm</a> %<b>in</b>% <a href="/source/s?defs=y" class="intelliWindow-symbol" data-definition-place="undefined-in-file">y</a> || <a class="d intelliWindow-symbol" href="#nm" data-definition-place="defined-in-file">nm</a> %<b>in</b>% <a class="d intelliWindow-symbol" href="#out" data-definition-place="defined-in-file">out</a>[<a href="/source/s?defs=seq_len" class="intelliWindow-symbol" data-definition-place="undefined-in-file">seq_len</a>(<a class="d intelliWindow-symbol" href="#i" data-definition-place="defined-in-file">i</a> - <span class="n">1</span>)]) {
<a class="l" name="167" href="#167">167</a>      <a class="d intelliWindow-symbol" href="#nm" data-definition-place="defined-in-file">nm</a> &lt;- <a href="/source/s?defs=paste0" class="intelliWindow-symbol" data-definition-place="undefined-in-file">paste0</a>(<a class="d intelliWindow-symbol" href="#nm" data-definition-place="defined-in-file">nm</a>, <a href="/source/s?defs=suffix" class="intelliWindow-symbol" data-definition-place="undefined-in-file">suffix</a>)
<a class="l" name="168" href="#168">168</a>    }
<a class="l" name="169" href="#169">169</a>
<a class="hl" name="170" href="#170">170</a>    <a class="d intelliWindow-symbol" href="#out" data-definition-place="defined-in-file">out</a>[[<a class="d intelliWindow-symbol" href="#i" data-definition-place="defined-in-file">i</a>]] &lt;- <a class="d intelliWindow-symbol" href="#nm" data-definition-place="defined-in-file">nm</a>
<a class="l" name="171" href="#171">171</a>  }
<a class="l" name="172" href="#172">172</a>  <a class="d intelliWindow-symbol" href="#out" data-definition-place="defined-in-file">out</a>
<a class="l" name="173" href="#173">173</a>}
<a class="l" name="174" href="#174">174</a></body>
</html>
